<?php
/**
 * Created by PhpStorm
 * User: Jhinwy
 * Date: 5/20/24
 * Time: 3:12 PM
 */

namespace App\Models;

use Illuminate\Support\Facades\Auth;
use Tymon\JWTAuth\Contracts\JWTSubject;
use Illuminate\Notifications\Notifiable;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Database\Eloquent\Factories\HasFactory;


class Admin extends Authenticatable implements JWTSubject
{
    use SoftDeletes, Notifiable, HasFactory;

    protected $table = 'admin';

    protected $fillable = [
        'name', 'account', 'password', 'last_ip', 'last_at', 'status'
    ];

    const AUTH_GUARD = 'admin';
    const TOKEN_TYPE = 'Bearer';

    const STATUS_ENABLE  = 1;
    const STATUS_DISABLE = 0;

    protected function serializeDate(\DateTimeInterface $date)
    {
        return $date->format('Y-m-d H:i:s');
    }


    /**
     * Get the identifier that will be stored in the subject claim of the JWT.
     *
     * @return mixed
     */
    public function getJWTIdentifier()
    {
        return $this->getKey();
    }


    /**
     * Return a key value array, containing any custom claims to be added to the JWT.
     *
     * @return array
     */
    public function getJWTCustomClaims()
    {
        return [];
    }


    /**
     * 配置Jwt-Auth验证表格的主键（默认ID）
     */
    public function getAuthIdentifierName()
    {
        return $this->primaryKey;
    }


    /**
     * 获取守卫
     *
     * @return \Illuminate\Contracts\Auth\Guard|\Illuminate\Contracts\Auth\StatefulGuard|Authenticatable
     */
    public static function setGuard()
    {
        return Auth::guard(self::AUTH_GUARD);
    }
}
